//package cn.netty.service;
//
//import com.alibaba.fastjson.JSONObject;
//import com.netty.websocket.MiscHelper;
//import cn.netty.spring.JdbcUtil;
//import org.apache.logging.log4j.LogManager;
//import org.apache.logging.log4j.Logger;
//
//public class OnlineUserBiz {
//    public Logger logger = LogManager.getLogger("[netty]"+getClass().getName());
//
//    //服务器重启后，见给所有Session 更新为 离线状态
//    public static void updateAllOffline(){
//        String sql = "\r\n update SecSessionInfo " +
//                "\r\n set IsOnline='0',ExitDate='"+ MiscHelper.getDateTime2()+"',ActiveDate='',PageTitle='',PageCode='',ActiveInfo=''" +
//                "\r\n where IsOnline='1'";
//        JdbcUtil.executeSql(sql);
//    }
//
//    public static void updateOnline(String sessionId,JSONObject data){
//        if (sessionId != null && sessionId.length()>5) {
//            String activeInfo=data.getString("activeInfo");if(MiscHelper.isNull(activeInfo) || activeInfo.equals("null"))activeInfo="";
//            if (activeInfo.length()>280)activeInfo=activeInfo.substring(0,280);//最多取280个字符
//            String isOnline = data.getString("isOnline");if(MiscHelper.isNull(isOnline) || isOnline.equals("null"))isOnline="1";
//
//            StringBuilder stringBuilder = new StringBuilder();
//            stringBuilder.append("UPDATE SecSessionInfo set IsOnline='"+isOnline+"',ExitDate='',ActiveDate='"+ MiscHelper.getDateTime2()+"'");
//            if (data.keySet().contains("pageTitle"))  stringBuilder.append(",PageTitle='"+data.getString("pageTitle")+"'");
//            if (data.keySet().contains("activeInfo")) stringBuilder.append(",\r\n ActiveInfo='"+activeInfo+"'");
//            if (data.keySet().contains("deviceType")) stringBuilder.append(",DeviceType='"+data.getString("deviceType")+"'");
//            if (data.keySet().contains("SocketId")) stringBuilder.append(",SocketSessionId='"+data.getString("SocketId")+"'");
//            stringBuilder.append(" where SessionId='" + sessionId + "'");
//            JdbcUtil.executeSql(stringBuilder.toString());
//        }
//    }
//    public static void updateOffline(String sessionId,JSONObject data){
//        if (sessionId != null && sessionId.length()>5) {
//            String sql = "\r\n update SecSessionInfo " +
//                    "\r\n set IsOnline='0',ExitDate='"+ MiscHelper.getDateTime2()+"',ActiveDate='',PageTitle='',PageCode='',ActiveInfo=''" +
//                    "\r\n where SessionId='" + sessionId + "'";
//            JdbcUtil.executeSql(sql);
//        }
//    }
//    public static void initOnline(JSONObject parameters,JSONObject data){
//        String sessionId = parameters.getString("sessionId");
//        String isOnline = data.getString("isOnline");
//
//        if (isOnline!=null && isOnline.equals("0")){
//            updateOffline(sessionId,data);
//        }else if (isOnline!=null && isOnline.equals("1")||isOnline.equals("2")) {
//            updateOnline(sessionId, data);
//        }
//    }
//}
